﻿@model WebUI.Models.StoreViewModel

<script src="~/Javascript/Summary.js" type="text/javascript"></script>
<script type="text/javascript" src="~/JSDatePicker/jsDatePick.full.1.3.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="~/JSDatePicker/jsDatePick_ltr.css" />
<link href="~/TableComponents/newDate.css" rel="stylesheet" />

<h3 style ="text-align: center">Store @Model.ID</h3>

<div id="ShowNewDate" style="display: none; float:left">
    @using (Html.BeginForm("AddDate", "Hours", new { id = Model.ID }, FormMethod.Post))
    {      
       <table class="imagetable">
            @{
                <thead><tr><td style ="text-align:center; background-color:whitesmoke"></td><td style ="text-align:center; background-color:whitesmoke">Opening Time - Closing Time</td><td style ="text-align:center; background-color:whitesmoke">Effective Date</td></tr></thead>
                var days = Model.Dates;
                for (int index = 0; index < days.Count; index++)
                {
                    int DoW = index + 1;
                    if (DoW == 7) { DoW = 0; }
                    ViewContext.Writer.Write(@"<tr><td>" + days[DoW].Name + @"</td><td>");
                    ViewBag.DayIndex = DoW;
                    Html.RenderPartial("_SelectDay", days);
                    ViewContext.Writer.Write(@"</td><td><input type='text' name='" + string.Format("effectiveDate{0}", DoW) + "' size='12' id='" + string.Format("DateField{0}", DoW) + "' /><img src='/JSDatePicker/img/calicon.jpg' /></td></tr>");   
                }
            }
        </table>
        <input id="submitButton" style="display:inline" type ="submit" value="Save" onclick="return summary.Submit()"/>
        <input type="button" value="Cancel" onclick = "summary.ToggleNewDate()"/> 
    }
</div>
<div id="ShowNewDateInsturctions" style="display: none">Each effective that is selected adds a new date to the upcoming store hours</div>
<input id ="addNewDateButton" type="button" style="display:inline" onclick = "summary.ToggleNewDate()" value="Add effective date" /> 



@Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "GridView";
        settings.CallbackRouteValues = new { Controller = "Hours", Action = "Details", id = Model.ID };
        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Hours", Action = "Delete" };
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        settings.Settings.ShowVerticalScrollBar = true;
        settings.Settings.VerticalScrollableHeight = 400;
        //settings.SettingsBehavior.ConfirmDelete = true;
        
        
        //settings.SettingsPager.Position = System.Web.UI.WebControls.PagerPosition.TopAndBottom;
        //settings.SettingsPager.FirstPageButton.Visible = true;
        //settings.SettingsPager.LastPageButton.Visible = true;
        //settings.SettingsPager.PageSizeItemSettings.Visible = true;
        //settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "6", "10", "20", "25" };
        
        
        settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
        settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
        settings.ControlStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
        

        settings.Columns.Add(col =>
        {
            col.FieldName = "EffectiveDateDisplay";
            col.Caption = "Effective Date";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Monday";
            col.FieldName = "MondayHours.DisplayFormat";
        }); 

        settings.Columns.Add(col =>
        {
            col.Caption = "Tuesday";
            col.FieldName = "TuesdayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Wednesday";
            col.FieldName = "WednesdayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Thursday";
            col.FieldName = "ThursdayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Friday";
            col.FieldName = "FridayHours.DisplayFormat";
        });

        settings.Columns.Add(col =>
        {
            col.Caption = "Saturday";
            col.FieldName = "SaturdayHours.DisplayFormat";
        });
        
        settings.Columns.Add(col =>
        {
            col.Caption = "Sunday";
            col.FieldName = "SundayHours.DisplayFormat";
        });

        settings.HtmlRowPrepared += (sender, e) =>
        {
            var effectiveDate = (DateTime)e.GetValue("EffectiveDate");
            var cssClass = "dxgvDataRow_DevEx";

            if (Model.CurrentHours.EffectiveDate != null && effectiveDate.Equals(Model.CurrentHours.EffectiveDate))
            {
                cssClass += "_current";
            }
            else
            {
                cssClass += effectiveDate < DateTime.Now ? "_old" : "_new";
                cssClass += e.VisibleIndex % 2 == 0 ? "_even" : "_odd";
            }

            e.Row.CssClass = cssClass;
        };


        //settings.KeyFieldName = "weeklyID";
    }).Bind(Model.AllHours).GetHtml()
